package com.edu.servlet;

import java.io.IOException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.edu.bean.Orders;
import com.edu.service.OrdersService;
import com.edu.service.impl.OrdersServiceImpl;
@WebServlet("/updateOrders.do")
public class UpdateOrdersServlet extends HttpServlet{
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		OrdersService os = new OrdersServiceImpl();
		String oid = req.getParameter("orderid");
		String uid = req.getParameter("userid");
		String cid = req.getParameter("carid");
		String date = req.getParameter("date");
		String price = req.getParameter("price");
		String state = req.getParameter("state");
		int orderid = Integer.parseInt(oid);
		int userid = Integer.parseInt(uid);
		int carid = Integer.parseInt(cid);
		DateFormat dft = new SimpleDateFormat("yyyy-MM-dd");
		Date orderdate=null;
		try {
			orderdate = dft.parse(date);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		double prices = Double.parseDouble(price);
		Orders or = new Orders(userid,carid,orderdate,prices,state,orderid);
		os.updateOrders(or);
	}
}
